package demo2;

import javax.security.sasl.SaslClient;
import java.util.Scanner;

/**
 * @author Huangjin
 * @version 1.0
 * describe:
 *  获取用户输入的价格、月份、选择机舱
 *  定义价格变量
 *  打折按照淡旺季，先判断在是使用switch进行计算
 *  最后返回最终的价格
 * @date 2023/2/20 19:01
 */
public class CalAirPrice {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入机票原价：");
        double price = sc.nextDouble();
        System.out.println("请输入月份：");
        int month = sc.nextInt();
        System.out.println("请选择机舱：1.头等舱 2.商务舱 3.经济舱");
        int type = sc.nextInt();
        double price0 = finalPrice(month,price,type);
        if (price0 != -1){
            System.out.println("优惠后的价格为："+price0);
        }

    }
    public static double finalPrice(int month,double price,int type){
        double price1 = 0.0;
        if (month<1 || month>12){
            System.out.println("月份输入错误");
            return -1;
        }
        if (month>=5 && month<=10){
            switch (type){
                case 1:
                    price1 = price*=0.9;
                    break;
                case 2:
                    price1 = price*=0.85;
                    break;
                case 3:
                    price1 = price*=0.8;
                    break;
                default:
                    System.out.println("机舱选择错误");
                    return -1;
            }
        }else {
            switch (type){
                case 1:
                    price1 = price*=0.7;
                    break;
                case 2:
                    price1 = price*=0.65;
                    break;
                case 3:
                    price1 = price*=0.6;
                    break;
                default:
                    System.out.println("机舱选择错误");
                    return -1;
            }
        }
        return price1;
    }
}
